package anthology.daily_question._24_11;
//https://leetcode.cn/problems/number-of-bit-changes-to-make-two-integers-equal/description/?envType=daily-question&envId=2024-11-02
public class _3226使两个整数相等的位更改次数 {
    //模拟
    public int minChanges(int n, int k) {
        int res = 0;
        while (n > 0 || k > 0){
            if ((n & 1) == 0 && (k & 1) == 1) {
                return -1;
            }
            if ((n & 1) == 1 && (k & 1) == 0) {
                res++;
            }
            n >>= 1;
            k >>= 1;
        }
        return res;
    }
    //位运算
    public int minChanges2(int n, int k) {
        return (n & k) == k ? Integer.bitCount(n ^ k) : -1;
    }
}
